package com.rear.controller;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.stereotype.Controller;

import com.rear.entity.TestTab1Entity;
import com.rear.service.TestTab1Service;
import com.rear.utils.PageUtils;
import com.rear.utils.R;


/**
 * ${comments}
 * 
 * @author October
 * @email chenzeming@9an-data.com
 * @date 2017-05-09 20:58:22
 */
@Controller
@RequestMapping("testtab1")
public class TestTab1Controller {
	@Autowired
	private TestTab1Service testTab1Service;
	
	@RequestMapping("/testtab1.html")
	public String list(){
		return "testtab1/testtab1.html";
	}
	
	/**
	 * 列表
	 */
	@ResponseBody
	@RequestMapping("/list")
	@RequiresPermissions("testtab1:list")
	public R list(Integer page, Integer limit){
		Map<String, Object> map = new HashMap<>();
		map.put("offset", (page - 1) * limit);
		map.put("limit", limit);
		
		//查询列表数据
		List<TestTab1Entity> testTab1List = testTab1Service.queryList(map);
		int total = testTab1Service.queryTotal(map);
		
		PageUtils pageUtil = new PageUtils(testTab1List, total, limit, page);
		
		return R.ok().put("page", pageUtil);
	}
	
	
	/**
	 * 信息
	 */
	@ResponseBody
	@RequestMapping("/info/{id}")
	@RequiresPermissions("testtab1:info")
	public R info(@PathVariable("id") Integer id){
		TestTab1Entity testTab1 = testTab1Service.queryObject(id);
		
		return R.ok().put("testTab1", testTab1);
	}
	
	/**
	 * 保存
	 */
	@ResponseBody
	@RequestMapping("/save")
	@RequiresPermissions("testtab1:save")
	public R save(@RequestBody TestTab1Entity testTab1){
		testTab1Service.save(testTab1);
		
		return R.ok();
	}
	
	/**
	 * 修改
	 */
	@ResponseBody
	@RequestMapping("/update")
	@RequiresPermissions("testtab1:update")
	public R update(@RequestBody TestTab1Entity testTab1){
		testTab1Service.update(testTab1);
		
		return R.ok();
	}
	
	/**
	 * 删除
	 */
	@ResponseBody
	@RequestMapping("/delete")
	@RequiresPermissions("testtab1:delete")
	public R delete(@RequestBody Integer[] ids){
		testTab1Service.deleteBatch(ids);
		
		return R.ok();
	}
	
}
